package com.ai.bitcoin.jpa.dao;

import com.ai.bitcoin.jpa.entity.BccBatch;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

/**
 * @author Jason
 * @date 2018/3/29
 **/
public interface BccBatchDao extends JpaRepository<BccBatch, String> {

    List<BccBatch> findByBatchTypeAndBatchStateAndBatchTimeEndLessThan(String bathType, String batchState, Date date);

    List<BccBatch> findByBatchTypeAndBatchStateOrderByBatchTimeEndDesc(String bathType, String batchState);

    @Query(nativeQuery = true, value = "SELECT * FROM bcc_batch WHERE batch_type=?1 AND batch_state=?2 ORDER BY batch_time_end DESC limit 1")
    BccBatch findOneByBatchTypeAndBatchStateOrderByBatchTimeEndDesc(String bathType, String batchState);
}